/*
package com.onepower.admin.core.security;

        import com.alibaba.fastjson.JSON;
        import com.fasterxml.jackson.databind.ObjectMapper;
        import com.onepower.core.domain.AuthUser;
        import com.onepower.core.modules.repository.entity.SysUser;
        import com.onepower.core.result.BaseResultCode;
        import com.onepower.core.result.CommonResult;
        import com.onepower.core.utils.JwtUtils;
        import com.onepower.core.utils.ResultUtils;
        import org.springframework.http.MediaType;
        import org.springframework.security.authentication.AuthenticationManager;
        import org.springframework.security.authentication.BadCredentialsException;
        import org.springframework.security.authentication.DisabledException;
        import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
        import org.springframework.security.core.Authentication;
        import org.springframework.security.core.AuthenticationException;
        import org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter;
        import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
        import org.springframework.security.web.util.matcher.AntPathRequestMatcher;

        import javax.servlet.FilterChain;
        import javax.servlet.ServletException;
        import javax.servlet.http.HttpServletRequest;
        import javax.servlet.http.HttpServletResponse;
        import java.io.IOException;

public class JWTLoginFilter extends AbstractAuthenticationProcessingFilter {


    public JWTLoginFilter(String url, AuthenticationManager authManager) {
        super(new AntPathRequestMatcher(url));
        setAuthenticationManager(authManager);
    }


    @Override
    public Authentication attemptAuthentication(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws AuthenticationException, IOException {
        SysUser creds = new ObjectMapper().readValue(httpServletRequest.getInputStream(), SysUser.class);

        // 返回一个验证令牌
        return getAuthenticationManager().authenticate(
                new UsernamePasswordAuthenticationToken(
                        creds.getAccount(),
                        creds.getPassword()
                )
        );
    }

    @Override
    protected void successfulAuthentication(
            HttpServletRequest httpServletRequest,
            HttpServletResponse httpServletResponse, FilterChain chain,
            Authentication auth) throws IOException {
        httpServletRequest.getSession().setMaxInactiveInterval(999999);
        httpServletResponse.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE);
        AuthUser authUser = (AuthUser) auth.getPrincipal();
        httpServletResponse.getWriter().write(JSON.toJSONString(ResultUtils.ok(JwtUtils.doGenerateToken(authUser))));
    }

    @Override
    protected void unsuccessfulAuthentication(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AuthenticationException failed) throws IOException {
        httpServletResponse.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE);
        CommonResult commonResult;
        if (failed instanceof BadCredentialsException) {
            commonResult = ResultUtils.error(BaseResultCode.ACCOUNT_PASSWORD_ERROR);
        } else if (failed instanceof DisabledException) {
            commonResult = ResultUtils.error(BaseResultCode.HAS_LOGIN);
        } else {
            commonResult = ResultUtils.error(BaseResultCode.SYSTEM_ERROR);
        }
        httpServletResponse.getWriter().write(JSON.toJSONString(commonResult));
    }
}
*/
